#include <iostream>
#include <unordered_map>
using namespace std;

string longestRepeatedSubstring(string str) {
    int n = str.length();
    unordered_map<string, int> countMap;

    for (int i = 0; i < n; i++) {
        string substring = "";
        for (int j = i; j < n; j++) {
            substring += str[j];
            countMap[substring]++;
        }
    }

    string longestSubstring = "";
    int maxLength = 0;

    for (auto it : countMap) {
        if (it.second > 1 && it.first.length() > maxLength) {
            maxLength = it.first.length();
            longestSubstring = it.first;
        }
    }

    return longestSubstring;
}

int main() {
    string str = "banana";  

    string result = longestRepeatedSubstring(str);
    cout << "The first longest repeated substring in the string is: " << result << endl;

    return 0;
}